package dream.dpx.pay.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import zhibi.frame.springmvc.interceptor.AdminInterceptor;
import zhibi.frame.springmvc.interceptor.LogInterceptor;
import zhibi.frame.springmvc.interceptor.ParamInterceptor;

import java.util.ArrayList;
import java.util.List;


@Configuration
public class WebConfig implements WebMvcConfigurer {

    /**
     * 不拦截
     */
    private static List<String> EXCLUDE_PATH_PATTERNS = new ArrayList<String>() {{
        add("/plugin/**");
    }};

    @Autowired
    private ParamInterceptor paramInterceptor;
    @Autowired
    private AdminInterceptor adminInterceptor;
    @Autowired
    private LogInterceptor logInterceptor;


    /**
     * 添加拦截器
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(paramInterceptor).addPathPatterns("/**");
        registry.addInterceptor(logInterceptor).addPathPatterns("/**")
                .excludePathPatterns(EXCLUDE_PATH_PATTERNS);
        adminInterceptor.setAdminLoginUrl("/sghluo/login");
        registry.addInterceptor(adminInterceptor)
                .addPathPatterns("/sghluo/**")
                .excludePathPatterns("/sghluo/login")
                .excludePathPatterns(EXCLUDE_PATH_PATTERNS);
    }


}
